(function() {
    /**
     * Get application available height
     */
    function getAppHeight() {
        return (function() {
            height = 0;
            adf.mf.el.getValue("#{deviceScope.hardware.screen.availableHeight}", 
                // success
                function(req, res) {
                    height = res[0]['value'];
                }, 
                // error
                function(req, res) {
                    console.log("getAppHeight(): Get application height failed " + adf.mf.util.stringify(res));
                }
            );
            return height;
        })();
    }
    
    /**
     * Get application available width
     */
     function getAppWidth() {
        return (function() {
            width = 0;
            adf.mf.el.getValue("#{deviceScope.hardware.screen.availableWidth}", 
                // success
                function(req, res) {
                    width = res[0]['value'];
                }, 
                // error
                function(req, res) {
                    console.log("getAppWidth(): Get application width failed " + adf.mf.util.stringify(res));
                }
            );
            return width;
        })();
    }
    
    /**
     * Create sketch canvas
     */
    makeDraw = function() {
        try {
            var drawElement = document.getElementById("simple_sketch");
            if (drawElement == null) {
                console.log("ERROR!! drawElement not found!");
            }
            var sigJq = $(drawElement);
            sigJq.attr("height", (getAppHeight()-80)); // set height
            sigJq.attr("width", getAppWidth()); // set width
            sigJq.sketch(); // create sketch
            
        } catch (problem) {
            console.log("ERROR!! Problem with verbatim code: " + problem);
        }
    }
    
    window.setTimeout(makeDraw, 250);
})();